<?php  session_start();
/**
* @package		Parents@School
* @copyright	                Copyright (C) 2008 Kristof Beckers. All rights reserved.
* @Version		2.0
* @license		GNU/GPL, see LICENSE.php
**/
include ("include/config.php");
require_once ("include/db.php");
include ("include/header.php");
?>
<head>
<link rel="stylesheet" href="../css/template_css.css" type="text/css"/> 
</head>

<body>
<?php
// username and password sent from form
$myusername=$_POST['username'];
$mypassword=$_POST['passwd'];

$sql="SELECT * FROM jos_users WHERE username='$myusername' ";
$result=mysql_query($sql);

while ($row = mysql_fetch_array($result)) {
   $username =  $row['username'];  
   $password = $row['password'];
   $usernameid = $row['id'];
  //echo "Dit zijn de gegevens uit de database<br><br>";
  //echo $username. "<br>";
  //echo $password."<br><br>";
   }
   

$part = explode(":",$password);
$salt = $part[1];
$encrypted_password = md5($mypassword . $salt).":".$salt;
//echo "Dit zijn de gegevens van het formulier.<br><br>";
//echo $encrypted_password.":".$salt."<br><br>";
;

$sql1="SELECT * FROM jos_users WHERE username='$myusername' AND password='$encrypted_password' ";
$result1=mysql_query($sql1);
// Mysql_num_row is counting table row
$count=mysql_num_rows($result1);
// If result matched $myusername and $mypassword, table row must be 1 row
if($count==1) {
// Register $myusername, $mypassword and redirect to file "login_success.php"
$sql2="SELECT * FROM jos_comprofiler WHERE id='$usernameid'";
$result2=mysql_query($sql2);
while ($row1 = mysql_fetch_array($result2)) {
		$klas = $row1['cb_klas'];
		}
$_SESSION['myusername'] = $myusername ;
$_SESSION['klas'] = $klas;
//session_register("myusername");
//session_register("mypassword");
if ($_SESSION['myusername'] == $admin){
	header("location:../admin/index.php");
	}
header("location:../reservatie.php");
}
else 
{
echo "Verkeerde gebruikersnaam en of wachtwoord";
}
mysql_close();
?>
</body>